package com.example.replacebooks.mapper;

import com.example.replacebooks.entity.Bookinfo;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface BookinfoMapper extends Mapper<Bookinfo> {
    List<Bookinfo> findBySearch(@Param("params") Params params,@Param("userid") Integer userid,@Param("role") Integer role);

    @Select("select bi.*,u.name from bookinfo bi left join user u on bi.userid = u.userid where bookid = #{bookid} limit 1")
    Bookinfo findByBookid(@Param("bookid") Integer bookid);

    @Select("select * from bookinfo where bookid = #{bookid}")
    List<Bookinfo> findByBookids(@Param("bookid") Integer bookid);

    @Select("select * from bookinfo where classid = #{classid}")
    List<Bookinfo> findByClassid(@Param("classid") Integer classid);

    @Update("update bookinfo set userid=#{userid},statu = #{statu},time = #{time},bookname = #{bookname},bookimg = #{bookimg},bookintro = #{bookintro},degree = #{degree},price = #{price},changebook = #{changebook},ISBN = #{isbn},userid = #{userid},classid = #{classid} where bookid = #{bookid}")
    void updateBybookid(Bookinfo bookid);

    List<Bookinfo> findByStatuSearch(@Param("params") Params params,@Param("userid") Integer userid,@Param("role") Integer role);

    List<Bookinfo> myaddbook(@Param("params") Params params,@Param("userid") Integer userid,@Param("role") Integer role);
}

